<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['basic']=$this->plugin_setting('basic');
$return['ischecklogin']=cfc('core')->checklogin('','',true);
$this->model('member')->upmember();
if($_RQ['op']=='main'){
	set_html('title','顾问中心');
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit5','credit6','mobile','groupid','avatar','nickname'));
	$this->model('model')->checklogin();	
	$user=pdo_get('jy_aixiaoyi_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$member=array_merge($member,$user);
	$member['avatar']=tomedia($member['avatar']);
	$return['member']=$member;
	$return['guwen']=pdo_get('jy_aixiaoyi_guwen',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$return['guwen']['sextitle']=$this->sex[$return['guwen']['sex']];
	if(!$return['guwen']){
		exi('您还不是顾问！','error','jy_aixiaoyi/home/');
	}
	$return['item']=array();
	exi($return);
}
if($_RQ['op']=='getlist'){
	$guwenid=pdo_getcolumn('jy_aixiaoyi_guwen',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');
	$params=array('uniacid'=>$_SESSION['uniacid'],'guwenid'=>$guwenid);
	$_RQ['page'] = $_RQ['page'] ? $_RQ['page'] : 1;
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_aixiaoyi_member',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['sextitle']=$this->sex[$item['sex']];
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='setinfo'){
	$post=get_postdata();
	if(!$post['title'] || !$post['sex'] || !$post['mobile']){
		exi('所有内容不能为空！');
	}
	$update=array(
		'mobile'=>$post['mobile'],
		'title'=>$post['title'],
		'sex'=>$post['sex'],
	);
	pdo_update('jy_aixiaoyi_guwen',$update,array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	exi('操作成功！');
}
if($_RQ['op']=='setcong'){
	$post=get_postdata();
	$congtime=intval($post['congtime']);
	if($congtime<=0){
		exi('请输入充值次数！');
	}
	$guwen=pdo_get('jy_aixiaoyi_guwen',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	if($guwen['shetimes']<$congtime){
		exi('充值次数不能大于当前剩余次数！');
	}
	pdo_update('jy_aixiaoyi_guwen',array('shetimes -='=>$congtime),array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	pdo_update('jy_aixiaoyi_member',array('shetimes +='=>$congtime),array('id'=>$post['id'],'uniacid'=>$_SESSION['uniacid']));
	exi('操作成功！');
}